package com.cb2.algorithm.leetcode;

/**
 * <a href='https://leetcode.cn/problems/reverse-string'>反转字符串(Reverse String)</a>
 * <p>编写一个函数，其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出。</p>
 * <p>不要给另外的数组分配额外的空间，你必须原地修改输入数组、使用 O(1) 的额外空间解决这一问题。</p>
 *
 * <p>
 * <b>示例：</b>
 * <pre>
 *  示例 1：
 *      输入：s = ["h","e","l","l","o"]
 *      输出：["o","l","l","e","h"]
 *
 *  示例 2：
 *      输入：s = ["H","a","n","n","a","h"]
 *      输出：["h","a","n","n","a","H"]
 * </pre>
 * </p>
 *
 * <p>
 *
 * <b>提示：</b>
 * <ul>
 *     <li>1 <= s.length <= 10^5</li>
 *     <li>s[i] 都是 ASCII 码表中的可打印字符</li>
 * </ul>
 * </p>
 *
 * @author c2b
 * @see LC0344ReverseString_S 反转字符串
 * @see LC0541ReverseString_II_S 反转字符串 II
 * @since 2025/2/7 14:56
 */
public class LC0344ReverseString_S {
    static class Solution {
        public void reverseString(char[] s) {
            for (int left = 0, right = s.length - 1; left < right; ++left, --right) {
                char temp = s[left];
                s[left] = s[right];
                s[right] = temp;
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        char[] chars1 = {'h', 'e', 'l', 'l', 'o'};
        solution.reverseString(chars1);
        char[] chars2 = {'H', 'a', 'n', 'n', 'a', 'h'};
        solution.reverseString(chars2);
    }
}
